home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 076-100 / disk_084 / ed / dodash.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  1KB  |  55 lines

  1. #include <stdio.h>
  2. #include "tools.h"
  3.  
  4. /*    Expand the set pointed to by *src into dest.
  5.  *    Stop at delim.  Return 0 on error or size of
  6.  *    character class on success.  Update *src to
  7.  *    point at delim.  A set can have one element
  8.  *    {x} or several elements ( {abcdefghijklmnopqrstuvwxyz}
  9.  *    and {a-z} are equivalent ).  Note that the dash
  10.  *    notation is expanded as sequential numbers.
  11.  *    This means (since we are using the ASCII character
  12.  *    set) that a-Z will contain the entire alphabet
  13.  *    plus the symbols: [\]^_`.  The maximum number of
  14.  *    characters in a character class is defined by maxccl.
  15.  */
  16. char *
  17. dodash(delim, src, map)
  18.  
  19. int    delim;
  20. char    *src, *map;
  21. {
  22.  
  23.     register int    first,    last;
  24.     char        *start;
  25.  
  26.     start = src;
  27.  
  28.     while( *src && *src != delim )
  29.     {
  30.         if( *src != '-')
  31.             setbit( esc( &src ), map, 1 );
  32.  
  33.         else if( src == start || *(src + 1) == delim )
  34.             setbit( '-', map, 1 );
  35.         else {
  36.             src++;
  37.  
  38.             if( *src < *(src - 2))
  39.             {
  40.                 first = *src;
  41.                 last = *(src - 2);
  42.             } else {
  43.                 first = *(src - 2);
  44.                 last = *src;
  45.             }
  46.  
  47.             while( ++first <= last )
  48.                 setbit( first, map, 1);
  49.  
  50.         }
  51.         src++;
  52.     }
  53.     return( src );
  54. }
  55.